import './request'
import axios from 'axios'

// const isDev = process.env.NODE_ENV === 'production'
const baseUrl = '/api/v1'

// 登陆接口
export const getLoginInfo = (loginInfo) => {
  return axios.post(`${baseUrl}/user/login`, {
    account: loginInfo.username,
    password: loginInfo.password
  })
}

// 获取商品
export const GetProduct = () => {
  return axios.get(`${baseUrl}/optimize_resume`)
}

// 创建订单
export const createOrder = (ProductId) => {
  return axios({
    method: 'post',
    url: `${baseUrl}/optimize_resume_order/create`,
    headers: {
      Authorization: `Bearer ${sessionStorage.getItem('apiToken')}`
    },
    params: {
      optimize_id: ProductId
    }
  })
}

// 微信支付
export const goPay = (orderId) => {
  return axios({
    method: 'post',
    url: `${baseUrl}/optimize_resume_order/pay_wx`,
    headers: {
      Authorization: `Bearer ${sessionStorage.getItem('apiToken')}`
    },
    params: {
      order_id: orderId,
      trade_type: 'MWEB'
    }
  })
}

// 订单列表

export const GetOrderList = (isPay = null) => {
  return axios({
    method: 'get',
    url: `${baseUrl}/optimize_resume_order`,
    headers: {
      Authorization: `Bearer ${sessionStorage.getItem('apiToken')}`
    },
    params: {
      status: isPay
    }
  })
}

// 查询订单
export const queryOrder = (orderId) => {
  return axios({
    method: 'post',
    url: `${baseUrl}/optimize_resume_order/query_pay_wx`,
    headers: {
      Authorization: `Bearer ${sessionStorage.getItem('apiToken')}`
    },
    params: {
      order_id: orderId,
      trade_type: 'MWEB'
    }
  })
}
